#!/usr/bin/env bash
##################################################################
##
##  Update dart api doc
##
##
##  Author: Chaobin Wu
##  Email : chaobinwu89@gmail.com
##
#################################################################
die() {
  echo "$*"
  exit 1
}
set -e

echo "clean previous data"
rm -rf doc/.vuepress/public/api
rm -rf doc/.vuepress/public/project

mkdir -p doc/.vuepress/public/project
echo "Generate flutter web sample"
cd fair/example
flutter build web && mv build/web ../../doc/.vuepress/public/project/hello_fair
cd ../../
if [ ! -d "doc/.vuepress/public/project/hello_fair" ]; then
  die "hello_fair generate failed"
fi
echo "Generate api doc"
dartdoc --input fair --output doc/.vuepress/public/api
if [ ! -d "doc/.vuepress/public/api" ]; then
  die "api generate failed"
fi

